Content starts here Cast Using a Custom XQuery Function
This page last changed on Feb 26, 2008.

eDocs Home > BEA AquaLogic Data Services Platform Documentation > Data Services Developer's Guide > Contents

How To Cast Using a Custom XQuery Function

This topic describes how to write a custom XQuery function to cast between elements of different data types in an update map.

Example

An example of a custom XQuery cast function is one that casts from integer to string. Suppose the logical data service's return type uses xsd:integer for the TELEPHONE_NUMBER element, while the underlying data source uses xsd:string.

Mapping from Integer to String

The mapping between the two TELEPHONE_NUMBER elements is initially disabled. The value from the return type is something like 4155551212, which can easily be converted between xsd:integer and xsd:string. Check the type casting chart in the XQuery 1.0 specification to make sure the cast you want to perform is allowed.

When you test the cast function, you also need to perform the opposite cast (in this case, xsd:string to xsd:integer).

To write a custom XQuery cast function:

  1. Click the Source tab.
  2. Write an XQuery function that takes an argument of the data type you are casting from and returns a value of the data type you are casting to, for example:
    declare function tns:intToString($theint as xs:integer) as xs:string {
                  xs:string($theint)
    };

    Assign your function to an XML namespace your logical data service uses. Be sure both the parameter and return type are valid XML Schema data types. Then, write a statement that performs the cast. 

  3. In the Update Map tab, click the element in the data source on the left.
    At this point, the element is disabled: . Its value is taken from the return type, so its XQuery expression looks something like this:
    fn-bea:value($CUSTOMER/TELEPHONE_NUMBER)

    Remember that the value from the return type is an xs:integer.

  4. Add your new cast function, using the existing expression as its argument, for example:
    tns:intToString(fn-bea:value($CUSTOMER/TELEPHONE_NUMBER))

    At this point, the update map should be completely enabled.

  5. If the disabled icon on the element does not disappear immediately, click another element in the update map.
  6. Test the update map cast to make sure it works as you expect.

See Also

Concepts
How To
Other Resources
Document generated by Confluence on Apr 28, 2008 15:57